<template>
	<view class="box">
		<view class="box-nr">
			<view class="box-tab">
				<view class="tab-item" :class="tabType == 1 ? 'bg-blue' : ''" @click="tabType=1">
					活动总结
				</view>
				<view class="tab-item" :class="tabType == 2 ? 'bg-blue' : ''" @click="tabType=2">
					活动打卡
				</view>
			</view>
			<view>
				<SummaryFrom v-if="tabType == 1"></SummaryFrom>
				<ActivePunch v-if="tabType == 2"></ActivePunch>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getaboutApi
	} from "@/api/system/index"
	import {
		uploadWork
	} from "@/api/system/user"

	import config from '@/config'
	import SummaryFrom from "@/pagesA/index/summaryFrom.vue"
	import ActivePunch from "@/pagesA/index/activePunch.vue"
	export default {
		components: {
			SummaryFrom,
			ActivePunch
		},
		data() {
			return {
				tabType: 1,
				baseUrl: config.baseUrl,
				form: {
					base: {
						targetNum: null,
						lastWeekNum: null,
						lastMonthNum: null,
						amount: null,
						sincerityNum: null,
						cycleNum: null,
						inviteNum: null,
						newlyNum: null,
						newlyClue: null
					},
					summary: null,
					improve: null,
					sceneImgs: null,
					activeId: null
				},
				fileList1: [

				],
				imgArr: [],
				rules: {
					'base.targetNum': {
						type: 'string',
						required: true,
						message: '请填写',
						trigger: ['blur', 'change']
					},
					'userInfo.sex': {
						type: 'string',
						max: 1,
						required: true,
						message: '请选择男或女',
						trigger: ['blur', 'change']
					},
				},

			}

		},
		created() {

			//因为提交给后台数据库的图片路径是不带域名的
			var obj = {
				status: 'success',
				message: '',
				url: "https://image.doyoad.com//upload/qiniu/images/20250310/c3d659853a3f531e44906872bea08c2d.jpg",
				image: '',
			}
			//然后把obj添加到fileList1中，这样图片就可以回显出来了
			this.fileList1.push(obj)

			this.getAboutData()
		},
		methods: {
			getAboutData() {
				getaboutApi().then(res => {
					if (!res.code) {
						this.content = res.data.content
					}
				})
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1);
				this.imgArr.splice(event.index, 1);
			},
			// 新增图片
			async afterRead(event) {

				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file);
				let fileListLen = this[`fileList${event.name}`].length;
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: "uploading",
						message: "上传中",
					});
				});
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url);
					console.log("wwww>>>", result)
					let item = this[`fileList${event.name}`][fileListLen];
					this[`fileList${event.name}`].splice(
						fileListLen,
						1,
						Object.assign(item, {
							status: "success",
							message: "",
							url: result.url,
						})
					);
					this.imgArr.push(result.url)
					fileListLen++;
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					uploadWork({
						'filePath': url
					}).then(res => {
						setTimeout(() => {
							resolve(res.data);
						}, 1000);
					})
					console.log(">>>ppp", this.fileList1)
					// let a = uni.uploadFile({
					// 	url: this.baseUrl+"/member/upload", // 仅为示例，非真实的接口地址
					// 	filePath: url,
					// 	name: "file",
					// 	formData: {
					// 		user: "test",
					// 	},
					// 	success: (res) => {
					// 		setTimeout(() => {
					// 			resolve(res.data.data);
					// 		}, 1000);
					// 	},
					// });
				});
			},
			submit() {
				this.$refs.uForm.validate().then(res => {
					uni.$u.toast('接口失败')
				}).catch(errors => {
					uni.$u.toast('接口失败')
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		// background-color: #c;
	}

	.box {

		.box-nr {
			background-color: #fff;

			.box-tab {
				width: 95%;
				margin: 0 auto;
				display: flex;
				justify-content: space-between;

				.tab-item {
					padding: 20rpx;
					width: 50%;
					border: 1px solid #ccc;
					text-align: center;
					background-color: #fff;
				}

				.bg-blue {
					background-color: #3764F9 !important;
				}
			}

			.box-item {
				width: 90%;
				margin: 0 auto;
				padding: 30rpx 0rpx;
			}
		}

		.summary-box {
			.title {
				padding: 10px 0rpx;
			}
		}

		.foot-box {
			margin-top: 30rpx;
		}
	}
</style>